<template>
    <div class="app-container">
        <div class="block">
            <el-row :gutter="20">
                <el-col :span="6">
                    <el-date-picker v-model="timeArray" type="daterange" align="right" unlink-panels
                        range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                        :picker-options="pickerOptions" size="mini">
                    </el-date-picker>
                </el-col>

                <el-col :span="4">
                    <el-select v-model="listQuery.criteria.inBoundStatus" placeholder="出入库" size="mini">
                        <el-option label="全部" value=""></el-option>
                        <el-option label="入库" value="0"></el-option>
                        <el-option label="出库" value="1"></el-option>
                    </el-select>
                </el-col>


                <el-col :span="4">
                    <el-input v-model="listQuery.criteria.inBoundResponsible" placeholder="客户/供应商"
                        size="mini"></el-input>
                </el-col>
                <el-col :span="4">
                    <el-input v-model="listQuery.criteria.inBoundNo" placeholder="入库单号" size="mini"></el-input>
                </el-col>
                <el-col :span="4">
                    <el-input v-model="listQuery.criteria.orderNum" placeholder="订单编号" size="mini"></el-input>
                </el-col>



                <el-col :span="6" style="margin-top: 10px;">
                    <el-button type="success" icon="el-icon-search" @click.native="search" size="mini">搜索</el-button>
                    <el-button type="primary" icon="el-icon-refresh" @click.native="reset" size="mini">重置</el-button>
                </el-col>
            </el-row>
        </div>

        <el-row>
      <el-col :span="20">
        <el-table :data="list" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row :header-cell-style="{'text-align':'center'}" :cell-style="{'text-align':'center'}"
          @current-change="handleCurrentChange">


          <el-table-column label="入库单号" :span="4">
            <template slot-scope="scope">
              {{ scope.row.inBoundNo }}
            </template>
          </el-table-column>
          <el-table-column label="订单号" :span="4">
            <template slot-scope="scope">
              {{ scope.row.orderNum }}
            </template>
          </el-table-column>
          <el-table-column label="出入库" :span="4">
            <template slot-scope="scope">
              {{ scope.row.inBoundStatus == 0 ? '入库' : '出库' }}
            </template>
          </el-table-column>

          <el-table-column  label="操作人" :span="4">
            <template slot-scope="scope">
              {{ scope.row.inBoundPerson }}
            </template>
          </el-table-column>
          <el-table-column label="所属仓库" :span="4">
            <template slot-scope="scope">
              {{ scope.row.houseName }}
            </template>
          </el-table-column>
          <el-table-column label="客户/供应商" :span="4">
            <template slot-scope="scope">
              {{ scope.row.inBoundResponsible }}
            </template>
          </el-table-column>
          <el-table-column label="时间" :span="4">
            <template slot-scope="scope">
              {{formatDate( scope.row.createTime )}}
            </template>
          </el-table-column>
          <el-table-column label="类型" :span="4">
            <template slot-scope="scope">
              {{ scope.row.inBoundType == 0 ? '采购' : '销售' }}
            </template>
          </el-table-column>
          

          <el-table-column label="操作" min-width="50px" :span="4">
            <template slot-scope="scope">
                <el-button type="text" size="mini" @click.native="showDetail(scope.row.inBoundTypeId,scope.row.inBoundType)">商品详情</el-button>
            </template>

          </el-table-column>




        </el-table>

        <el-pagination background layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 50, 100, 500]"
          :page-size="listQuery.size" :total="total" :current-page.sync="listQuery.current" @size-change="changeSize"
          @current-change="fetchPage" @prev-click="fetchPrev" @next-click="fetchNext">
        </el-pagination>

      </el-col>
    </el-row>



    <el-dialog title="商品详情" :visible.sync="formVisible" width="70%" :modal-append-to-body="true">
      <el-row>
        <el-col :span="24">
          <el-table :data="goodsDetailList" style="width: 100%;margin-bottom: 20px;" row-key="id" border
            element-loading-text="Loading" fit highlight-current-row :default-expand-all="false">
            <el-table-column label="配图" align="center">
              <template slot-scope="scope">
                <img :src="`${baseUrl}file/getFileByGoodsId/${scope.row.id}?${generNum()}`" alt="加载失败" class="avatar"
                  style="max-height: 50px;max-width: 120px;">
              </template>

            </el-table-column>
            <el-table-column label="商品名称" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>

            <el-table-column label="商品价格" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.price / 100 }}元</span>
              </template>
            </el-table-column>
            <el-table-column label="价格单位" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.priceUnit }}</span>
              </template>
            </el-table-column>
            <el-table-column label="商品类型" align="center">
              <template slot-scope="scope">
                <span>{{ getTypeValueDict(scope.row.type) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="商品规格" align="center">
              <template slot-scope="scope">
                <el-tag :key="tag" v-for="tag in scope.row.specification" size="mini">
                  {{ tag }}
                </el-tag>
              </template>
            </el-table-column>

            <el-table-column label="商品数量" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.total }}</span>
              </template>
            </el-table-column>


          </el-table>
        </el-col>
      </el-row>

    </el-dialog>


    </div>
</template>

<script src="./stock.js">
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>